using System;
using System.Drawing;

namespace PocketPC_AdventureGame
{
	/// <summary>
	/// Summary description for Player.
	/// </summary>
	public class Player : GameObject
	{
		private Game game;

		public GoalActions goalAction = GoalActions.NONE;
		public enum GoalActions 
		{
			NONE,
			PICK_UP,
			DROP
		}

		private GameObject actionObject1;

		public Player(Game _game, Bitmap _sprite): base("Player", _sprite)
		{
			game = _game;
		}

        /// <summary>
        /// Scale player with location map.
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            //store old position/scale
            Rectangle oldPos = position;

            //get feet location
            Location l = game.GetLocatationAt(position.X + position.Width, position.Y + position.Height / 2);

            //scale based on location map.
            if (l != null)
            {
                byte scale = l.distance;
                position.Width = (originalWidth * scale) / 255;
                position.Height = (originalHeight * scale) / 255;
                position.X += (originalWidth - position.Width);
                position.Y += (originalHeight - position.Height) / 2;
            } 
            base.Draw(g);

            //restore scale for moving
            position = oldPos;
        }

		public void setGoalAction( GoalActions action, GameObject _actionObject1 ) 
		{
			goalAction = action;
			actionObject1 = _actionObject1;
		}

        /// <summary>
        /// Called when a moving player reaches its goal.
        /// </summary>
		protected override void OnArrivedAtGoal()
		{
			if( goalAction == GoalActions.PICK_UP ) 
			{
				game.PickUp(actionObject1);
			}
			else if( goalAction == GoalActions.DROP ) 
			{
				game.Drop(actionObject1);
			}
			goalAction = GoalActions.NONE;
			actionObject1 = null;
		}


		/// <summary>
		/// Overridden because use of feet as origo and use location map.
		/// </summary>
		/// <param name="x"></param>
		/// <param name="y"></param>
		public override void MoveTo( int x, int y ) 
		{
			Location loc = game.FindClosestLocation(x,y);
			base.MoveTo( 10*loc.x - position.Width, 10*loc.y  - position.Height/2 );
		}


	}
}
